<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
const arr = [3,2,1,4,5]
let temp = arr[2]
arr[2] = arr[0]
arr[0] = temp
// 将数组中的  元素1  与  元素3 调换位置
{
    [arr[0],arr[2]]=[arr[2],arr[0]]
}
console.log(arr);
// 使用冒泡排序（从大到小）：  [90,65,78,66,48,39,92,73]  使用数组解构的方法交换变量
const arr1 =[90,65,78,66,48,39,92,73]
for (let i = 0; i < arr1.length-1; i++) {
    for (let j = 0; j < arr1.length-1; j++) {
        if (arr1[j]<arr1[j+1]) {
        [arr1[j],arr1[j+1]]=[arr1[j+1],arr1[j]]
        }
    }
}
console.log(arr1);
// var text =
// 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'
// //将上述字符串去除标点空格后统计有多少个单词
const str='I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'
// var str1=str.replace(',','')
// var str2=str1.replace('.','')
var word=str.split(' ')
console.log(word.length+'个单词');


const arr2 = [87,85,74,70,65,59,43]
// 1.移除第一个元素87，并在开头添加 元素86
arr2.splice(0,1,86)
console.log(arr2);
// 2.移除最后一个元素43， 并在末尾添加1
arr2.pop()
arr2.push(1)
console.log(arr2);
// 3.在 70 65 之间插入 元素 68
arr2.splice(4,0,68)
console.log(arr2);
// 4.删除元素65
arr2.splice(5,1)
console.log(arr2);
// 5.使用map返回一个新的数组new_arr，要求新数组new_arr比原来数组大2
var new_arr=arr2.map((item,index,arr)=>{
    return item+2;
})
console.log(new_arr);
// 6.筛选数组new_arr返回new_arr1,要求new_arr1: 能被2整除
var new_arr1=new_arr.filter((item,index,arr)=>
    item%2==0
)
console.log(new_arr1);
</script>
</head>
<body>
    
</body>
</html>